package br.uff.mic1.model;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class MemoriaDeControle {

	public final static int NUMERO_DE_LINHAS = 256;
	public final static int TAMANHO_LINHA = 32;
	
	public String[] memoria = new String[MemoriaDeControle.NUMERO_DE_LINHAS];
	
	public MemoriaDeControle()
	{
	}
	
	public MemoriaDeControle(String microprograma)
	{
		this.carregar(microprograma);
	}
	
	public void carregar(String microprograma)
	{
		try 
		{
			Scanner arquivo = new Scanner(new FileInputStream(microprograma));		
			int i = 0;
			while(arquivo.hasNextLine()) 
			{
				this.memoria[i] = arquivo.nextLine();
				i++;
			}
		} 
		catch(FileNotFoundException e) 
		{
			System.out.println("Arquivo do microprograma nao localizado.");
		}
	}
	
	public String getMicroinstrucao(String address)
	{
		return this.memoria[Integer.parseInt(address, 2)];
	}
	
}
